<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <a-input placeholder="请输入手机号" v-model="queryParam.phoneNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="账号子母">
              <a-input placeholder="请输入账号子母" v-model="queryParam.phoneType"></a-input>
            </a-form-item>
          </a-col>
        <template v-if="toggleSearchStatus">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.nickName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="区域">
              <a-input placeholder="请输入区域" v-model="queryParam.city"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="抖音账户">
              <a-input placeholder="请输入抖音账户" v-model="queryParam.douAccount"></a-input>
            </a-form-item>
          </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <!-- {{instanceId}}--{{imgId}} -->
     

      <a-button type="primary" icon="download" @click="handleExportXls('账户管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
       <a-button @click="handleDeleteM" type="primary" icon="plus">停止并删除母盘</a-button>
      <!-- <a-button @click="handleCreateM" type="primary" icon="plus">创建母盘</a-button>
      <a-button @click="handleRemote" type="primary" icon="plus">远程链接</a-button>
      <a-button @click="handleInstallApp1" type="primary" icon="plus">安装1</a-button>
      <a-button @click="handleInstallApp1" type="primary" icon="plus">安装2</a-button>
      <a-button @click="handleSaveImg" type="primary" icon="plus">保存IMG</a-button>
      <a-button @click="handleListImg" type="primary" icon="plus">查看IMG</a-button>
      <a-button @click="handleDeleteM" type="primary" icon="plus">停止并删除母盘</a-button>
      <a-button @click="handleDeleteImg" type="primary" icon="plus"> 删除IMG</a-button> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
                <a-menu-item>
                 <a @click="handleEdit(record)">编1辑</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

        <span slot="imgAction" slot-scope="text, record"> 
          <a v-if="text==null" @click="handleCreateLogin(record)">创建登录盘</a> 
          <span v-if="text!=null">{{text}}</span> 
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <phoneAccount-modal ref="modalForm" @ok="modalFormOk"></phoneAccount-modal>
    <log-modal ref="logmodal" @ok="passwordModalOk"></log-modal> 
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import PhoneAccountModal from './modules/PhoneAccountModal' 
  import LogModal from './modules/LogModal'
   
  import { JeecgListMixin } from '@/mixins/JeecgListMixin' 
  import {   postAction  } from '@/api/manage'

  export default {
    name: "PhoneAccountList",
    mixins:[JeecgListMixin],
    components: {
      PhoneAccountModal,LogModal
    },
    data () {
      return {
        description: '账户管理管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '手机号',
            align:"center",
            dataIndex: 'phoneNo'
           },
		   {
            title: '账号子母',
            align:"center",
            dataIndex: 'phoneType'
           },
		   {
            title: '昵称',
            align:"center",
            dataIndex: 'nickName'
           },
		   {
            title: '区域',
            align:"center",
            dataIndex: 'city'
           },
		   {
            title: '抖音账户',
            align:"center",
            dataIndex: 'douAccount'
           },
		  //  {
      //       title: '抖音密码',
      //       align:"center",
      //       dataIndex: 'douPassword'
      //      },
		   {
            title: '逗猫账户',
            align:"center",
            dataIndex: 'maoAccount'
           },
		  //  {
      //       title: '逗猫密码',
      //       align:"center",
      //       dataIndex: 'maoPassword'
      //      },
		   {
            title: '镜像ID',
            align:"center",
            dataIndex: 'imgId',
            scopedSlots: { customRender: 'imgAction' }, 
           },
		  //  {
      //       title: '所属部门编码',
      //       align:"center",
      //       dataIndex: 'sysOrgCode'
      //      },
		  //  {
      //       title: 'tenantId',
      //       align:"center",
      //       dataIndex: 'tenantId'
      //      },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/phone/phoneAccount/list",
          delete: "/phone/phoneAccount/delete",
          deleteBatch: "/phone/phoneAccount/deleteBatch",
          exportXlsUrl: "phone/phoneAccount/exportXls",
          importExcelUrl: "phone/phoneAccount/importExcel",
          createM: "phone/phoneAccount/createAppImg",
          remote: "phone/phoneAccount/remote",
          installApp1: "phone/phoneAccount/installApp1",
          installApp2: "phone/phoneAccount/installApp2",
          saveImg: "phone/phoneAccount/saveImg",
          listImg: "phone/phoneAccount/listImg",
          delImg: "phone/phoneAccount/delImg",
          deleteM: "phone/phoneAccount/deleteM",
          createLogin: "phone/phoneAccount/createLogin",
           
       },
    instanceId:"cp-bp112zfukukdsxgcj6f5",
    imgId:" ",
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: { 
     handleCreateM: function(){
         var   params = {
            instanceId  : this.instanceId
          } 
        postAction(`${window._CONFIG['domianURL']}/${this.url.createM}`, params).then((res) => {
          if (res.success) {
            this.instanceId = res.message;
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
        
      return null;
     },
     handleRemote: function(){
          var   params = {
            instanceId  : this.instanceId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.remote}`, params).then((res) => {
          if (res.success) {
            
            this.$message.success(res.result)
             window.open(res.result,"_blank");
          } else {
            this.$message.warning(res.message)
          }
        }) 
      
      
     },
     handleInstallApp1: function(){
            var   params = {
            instanceId  : this.instanceId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.installApp1}`, params).then((res) => {
          if (res.success) {
            
            this.$message.success(res.result)
             
          } else {
            this.$message.warning(res.message)
          }
        }) 
     },
     handleInstallApp2: function(){
           var   params = {
            instanceId  : this.instanceId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.installApp2}`, params).then((res) => {
          if (res.success) {
            
            this.$message.success(res.result)
             
          } else {
            this.$message.warning(res.message)
          }
        }) 
     },
     handleSaveImg: function(){
     
          var   params = {
            instanceId  : this.instanceId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.saveImg}`, params).then((res) => {
          if (res.success) {
            
            this.$message.success(res.result)
          } else {
            this.$message.warning(res.message)
          }
        }) 
     } ,
     handleListImg: function(){
         var   params = {}
        postAction(`${window._CONFIG['domianURL']}/${this.url.listImg}`, params).then((res) => {
          if (res.success) {
            var imgName   = []
            var list = JSON.parse(res.result).images.image;
            list.forEach((val, index) => {
              
              if(val.imageId!="android_9_0_0_release_3285106_20220531.raw"){
                this.imgId = val.imageId;
                imgName.push(val.imageId)
              }
              
            });
            this.$message.success(imgName.join(","))
          } else {
            this.$message.warning(res.message)
          }
        }) 
     } ,
     handleDeleteM: function(){
          var   params = {
            instanceId  : this.instanceId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.deleteM}`, params).then((res) => {
          if (res.success) {
             
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        }) 
     } ,
     handleDeleteImg: function(){
          var   params = {
            imageId  : this.imgId
          }
        postAction(`${window._CONFIG['domianURL']}/${this.url.delImg}`, params).then((res) => {
          if (res.success) {
             
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        }) 
     }  ,
     handleCreateLogin: function(record){ 
        console.log("ddddddddd");
        
        postAction(`${window._CONFIG['domianURL']}/${this.url.createLogin}`, record).then((res) => {
          if (res.success) {
            //  this.$refs.logmodal.show(record);
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        }) 
     } 
     
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  
 
</style>